import GlayerIndex from './GlayerIndex';
import {XYZ,WMTS,TileArcGISRest,Raster as RasterSource} from "ol/source";
import WMTSTileGrid from "ol/tilegrid/WMTS";
import {get as getProjection} from 'ol/proj';
import {getWidth, getTopLeft} from 'ol/extent';
import {ImageArcGISRest} from "ol/source";
import {Image as ImageLayer,Tile as TileLayer} from "ol/layer";

let mapkey = 'fbf3c9d252b16f57b182038368bc4813';
let projection = getProjection('EPSG:4326');
let projectionExtent = projection.getExtent();
let size = getWidth(projectionExtent) / 236;
let resolutions = new Array(18);
let matrixIds = new Array(18);
for (let z = 1; z < 19; ++z) {
	// generate resolutions and matrixIds arrays for this WMTS
	resolutions[z] = size / Math.pow(2, z);
	matrixIds[z] = z;
}

class GbaseLayers {
  constructor() {
    this.white = new TileLayer({
      extent: [7107053.740285003, -80822.9193149989, 16061315.281015012, 8587942.610615],
      source: new TileArcGISRest({
        url: "http://lbsapi.cindata.cn/gis/v2/services/export",
        params: {
          mapCode: '1_base_map_fe9e51abd96b7a041ab6f883eda91349',
          keyCode: '78b8c098b5694cf09fcd9b18ce94e7e7'
        }
      }),
      id: 'base',
      zIndex: GlayerIndex.BASE
    });
    this.black = new TileLayer({
      preload: 80,
      extent: [7107053.740285003, -80822.9193149989, 16061315.281015012, 8587942.610615],
      source: new TileArcGISRest({
        url: "http://lbsapi.cindata.cn/gis/v2/services/export",
        params: {
          mapCode: '1_base_map_96c539ec3ad278d85b9c572c5abcb7cf',
          keyCode: '78b8c098b5694cf09fcd9b18ce94e7e7'
        }
      }),
      id: 'base',
      zIndex: GlayerIndex.BASE
    });
    this.ChinaPolarNightBlue = new TileLayer({
      source: new TileArcGISRest({
        url: "http://tilesvc.cindata.cn/arcgis/rest/services/comm/ChinaPolarNightBlue/MapServer",
      }),
      id: 'base',
      zIndex: GlayerIndex.BASE
    });
    this.img = new TileLayer({
      source: new TileArcGISRest({
        url: "http://tilesvc.cindata.cn/arcgis/rest/services/comm/googleMapNew/MapServer",
      }),
      id: 'base',
      zIndex: GlayerIndex.BASE
    });
    this.TDT_VEC = [
      new TileLayer({
        extent:  [72, 3, 136, 54],
        source: new WMTS({
          //设置crossOrigin
          crossOrigin: "anonymous",
          url: 'http://t{0-7}.tianditu.gov.cn/vec_c/wmts?tk=' + mapkey, //mapkey为天地图密钥
          layer: 'vec',
          matrixSet: 'c',
          format: 'tiles',
          style: 'default',
          projection: projection,
          tileGrid: new WMTSTileGrid({
          origin: getTopLeft(projectionExtent),
          resolutions: resolutions,
          matrixIds: matrixIds
          }),
          wrapX: false,
        }),
        id: 'base',
        zIndex: GlayerIndex.BASE
      }),
      new TileLayer({
        extent:  [72, 3, 136, 54],
        source: new WMTS({
          crossOrigin: "anonymous",
          url: 'http://t{0-7}.tianditu.gov.cn/cva_c/wmts?tk=' + mapkey, //mapkey为天地图密钥
          layer: 'cva',
          matrixSet: 'c',
          format: 'tiles',
          style: 'default',
          projection: projection,
          tileGrid: new WMTSTileGrid({
          origin: getTopLeft(projectionExtent),
          resolutions: resolutions,
          matrixIds: matrixIds
          }),
          wrapX: false,
        }),
        id: 'base',
        zIndex: GlayerIndex.BASE
      })
    ];
    this.TDT_IMAGE = new TileLayer({
      source: new XYZ({
        url: 'http://t0.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=' + mapkey, //mapkey为天地图密钥
        wrapX: false,
      }),
      id: 'base',
      zIndex: GlayerIndex.BASE
    });
    this.HistoryImage =  [
    //   new ImageLayer({
    //   source: new ImageArcGISRest({
    //     crossOrigin: "anonymous",
    //     ratio: 1,
    //     params: {},
    //     url: netUrl + 'arcgis/rest/services/hshmap_2015/MapServer'
    //   }),
    //   id: 'base',
    //   zIndex: GlayerIndex.BASE
    // }),
       new TileLayer({
        source: new TileArcGISRest({
          // crossOrigin: "anonymous",
          url: localStorage.getItem("baseUrl"),
          cacheSize: 10240,
          params: {
           DPI: 50,
          }
        }),
         id: 'base',
         zIndex: GlayerIndex.BASE
      })
    ];
    // this.HistoryImage =  [
    //   new TileLayer({
    //     extent:  [72, 3, 136, 54],
    //     source: new WMTS({
    //       //设置crossOrigin
    //       crossOrigin: "anonymous",
    //       url: netUrl + 'arcgis/rest/services/hshmap_2015/MapServer',
    //       matrixSet: 'EPSG:3857', //投影坐标系设置矩阵
    //       format: 'image/png', //图片格式
    //       style: 'default',
    //       projection:  projection,
    //       //瓦片网格对象
    //       tileGrid:  new WMTSTileGrid({
    //         origin: getTopLeft(projectionExtent), //原点（左上角）
    //         resolutions: resolutions, //分辨率数组
    //         matrixIds: matrixIds //矩阵标识列表，与地图级数保持一致
    //       }),
    //       wrapX: true
    //     }),
    //     id: 'base',
    //     zIndex: GlayerIndex.BASE
    //   }),
    // ];
  }
}
export default GbaseLayers;
